Skip to content

feat(auth): add opt-in SAML federation through a trusted broker - #72

Merged
ALikesToCode merged 3 commits into
feat/tenant-governancefrom
feat/saml-federation
Oct 9, 2026
Merged

ALikesToCode merged 3 commits into
feat/tenant-governancefrom
feat/saml-federation

Conversation

@ALikesToCode

Copy link
Copy Markdown
Owner

Summary

Adds opt-in SAML login through an operator-run SAML broker. The gateway never parses SAML XML. The broker validates the IdP response and returns a compact signed token, which the gateway verifies against pinned keys. With SAML_ENABLED unset or off (the default), every /auth/saml/* and subject-link route returns 404 before any session, CSRF or storage work, and nothing else changes.

  • Settings:
    • SAML_ENABLED. Empty means off; a malformed value is off with one warning that leaves the value out.
    • SAML_BROKER_URL is the HTTPS broker address.
    • SAML_CALLBACK_URL pins the expected recipient independently of request headers.
    • SAML_TRUST_CONFIG_JSON holds {issuer, audience, keys: [{kid, alg, public_key_pem}], max_age_seconds ≤ 300}.
    • Invalid values disable federation with one warning.
  • Verification (installed cryptography only):
    • Each key ID is pinned to RS256 (2,048-bit or larger) or EdDSA.
    • none, HMAC, unknown and mismatched algorithms are rejected.
    • Issuer, audience, recipient, nonce, state, iat/exp (lifetime of at most 300 s, small fixed skew) and optional nbf are checked.
  • Flow:
    • GET /auth/saml/login stores digests of a random nonce and state, binds the state to the browser session, and redirects only to the configured broker.
    • /auth/saml/callback verifies the token and claims the nonce exactly once; a replay returns 400 saml_assertion_replayed.
    • The verified (issuer, subject) must match an operator-created link to an existing account; otherwise it returns 403 saml_subject_unlinked.
    • There are no just-in-time accounts and no administrator grants from assertion attributes.
  • Session: the dashboard session is issued through a named collaborator. Until the Wave 7 integration connects it, login fails closed with 503 saml_session_unavailable.
  • Native SAML: /auth/saml/acs and /auth/saml/metadata return 503 saml_native_unavailable. Native SAML needs a reviewed XML signature dependency, which is not installed.
  • Subject links: GET/PUT /admin/saml/links and GET/PUT/DELETE /admin/saml/links/<id> need an administrator session and CSRF, and write audit rows. DELETE deactivates and keeps history.
  • Storage: D1 only (migration 0035). Missing storage returns 503 saml_storage_unavailable and never admits a login.

Details are in docs/saml-federation.md.

Wiring

All new files; no existing file changes. The Worker forwards /auth/saml/* to the Container unchanged, which a test confirms. The Wave 7 integration adds these:

  • mounting register_saml_federation_routes;
  • the private saml store endpoint and its dispatcher entry;
  • the public endpoint allowlist for the login guard;
  • the session issuer.

Shared registrations

  • tests/test_saml_federation_worker.mjs in test:worker.
  • worker/saml-identity.mjs in the edge module inventory, and the six SAML routes in the Flask route inventory.
  • SAML_ENABLED, SAML_BROKER_URL, SAML_TRUST_CONFIG_JSON and SAML_CALLBACK_URL in the Container env keys.
  • saml_requests, saml_subject_links and saml_audit in REQUIRED_D1_TABLES.

Stacked on #71

Migration numbers must be contiguous in each PR, so this branch merges feat/tenant-governance (#71, migration 0034), which stacks on #70 (0033). Merge those first. SCIM provisioning stacks on this one.

Tests

  • tests/test_saml_federation.py and tests/test_saml_federation_worker.mjs cover:
    • the 404 while disabled, and the broker redirect allowlist;
    • valid tokens, and wrong issuer, audience, recipient, nonce, key or algorithm;
    • expiry and replay;
    • no just-in-time administrator, and tenant binding;
    • native ACS and metadata returning 503;
    • Worker forwarding of the SAML URL, method, cookies and token body.
  • Full Python suite: 4,903 passed, 2 skipped. ruff, mypy and bandit are clean.
  • npm run test:worker: 1,821 passed. npm run test:integration: 7 passed.
  • cf:migrations:check reports 35 contiguous, additive migrations. test:deploy, free routes, client headers and the wrangler deploy --dry-run bundle all pass.
  • tests/test_frontend_build.mjs fails locally because @tailwindcss/cli is not installed. It fails the same way on main.

Apply the migration before enabling the flag: npx wrangler d1 migrations apply multillm-intelligence --remote.

CI notes

  • GitHub python/node jobs: the dependency-audit steps fail on every branch, including main. fix(deps): clear the CI dependency audit advisories #42 fixes that.
  • Workers Builds: fails on this stack because the Wave 3 base adds the AdmissionCoordinator Durable Object migration, which wrangler versions upload cannot apply. This is expected until wrangler deploy runs on main.

This is part of Wave 7. The README line comes with the Wave 7 integration PR.

SAML_ENABLED (off by default) adds broker-backed dashboard login. The gateway
never parses SAML XML: an operator-run broker returns a compact JWS that is
verified against pinned RS256 or Ed25519 keys and bound to the issuer,
audience, recipient, nonce and browser state. Each request nonce is claimed
once, and only an operator-created subject link maps a verified subject to an
existing account, with no just-in-time accounts or administrator grants.

Native ACS and metadata return 503 saml_native_unavailable. Request state,
subject links and audit rows live in D1 (migration 0035).
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f13ddd1e-558e-47c0-9a6e-51d818a7e80a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
multillm-proxy 0c9d36f Oct 09 2026, 07:59 AM

@ALikesToCode
ALikesToCode merged commit 5a1ed49 into feat/tenant-governance Oct 9, 2026
4 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant